package com.example.sekerim;
 
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

/**
 * Used for storing application specific data in the phone memory
 * Values are specific to the current user
 *
 */
public class SaveSharedPreference {
	/**
	 * mail address of the one whose session is active
	 */
	static final String PREF_MAIL_ADDRESS = "mailAddress";

	static SharedPreferences getSharedPreferences(Context ctx) {
		return PreferenceManager.getDefaultSharedPreferences(ctx);
	}

	/**
	 * saves a new mail address
	 * @param ctx context of the current activity
	 * @param mail address of the current student
	 */
	public static void setMailAddress(Context ctx, String mailAddress) 
	{
		Editor editor = getSharedPreferences(ctx).edit();
		editor.putString(PREF_MAIL_ADDRESS, mailAddress);
		editor.commit();
	}

	public static String getMailAddress(Context ctx)
	{
		return getSharedPreferences(ctx).getString(PREF_MAIL_ADDRESS, "");
	}

	/**
	 * Remove student id when logout
	 * @param ctx Context of the current activity
	 */
	public static void removeMailAddress(Context ctx){
		Editor editor = getSharedPreferences(ctx).edit();
		editor.remove(PREF_MAIL_ADDRESS);
		editor.commit();
	}

}
